<?php
namespace View;
class BloggView {
	private $title = "title";
	private $post = "post";
	private $submit = "submit";
	private $editSubmit = "editsubmit";
	private $delete = "delete";
	private $edit = "edit";
	private $poste = '';
	private $titlee = '';
	const NOT_EMPTY = 0;
	const POST_PASSED = 1;
	const POST_FAILED = 2;
	const POST_DELETED = 3;
	const POST_NOT_DELETED = 4;
	const POST_SAVED = 5;
	//Skapar html för att visa en post
	public function showPost(\Model\Blogg $blogg) {
		$commentView = new \View\CommentView();
		$listLink = \View\NavigationView::getPostList();
		$title1 = $blogg -> getTitle();
		$date = $blogg -> getDate();
		$post1 = $blogg -> getPost();
		return "
				<div class='post'>
						<h2 class='title'>$title1</h2>
						<p class='meta'>Posted on $date &nbsp;&bull;&nbsp; 
						<a href='#' class='comments'>Comments ()</a> </p>
						<div class='entry'>
							<p>$post1</p>
						</div>
						<h3><a href='$listLink'>Back to list</a></h3>
				</div> 
		";

	}
	//Skapar html för två knappar
	function EditSelectedPost() {
		return "<div> 
					<form method='post' action=''></br> 
						<input type='submit' class='css3button' value='Delete' name='$this->delete'/>
						<input type='submit' class='css3button' value='Edit' name='$this->edit'/>  
					</form>
				</div>";
	}
	//Skapar html för att visa alla poster
	public function ShowListOfPosts(\Model\BloggArray $bloggArray) {
			$ret = "";
		foreach ($bloggArray->get() as $blogg) {
			$linkToPost = NavigationView::getPostLink($blogg);
			$ret .= "<div class='post'>";
			$ret .= "<h2 class='title'><a href='$linkToPost'>" . $blogg -> getTitle() . "</a></h2>";
			$ret .= "<p class='meta'>Posted on " . $blogg->getDate() . " &nbsp;&bull;&nbsp; 
						<a href='#' class='comments'>Comments ()</a>  &nbsp;&bull;&nbsp; <a href='$linkToPost' class='permalink'>Full article</a></p>"; 
			$ret .= "<div class='entry'><p>" . $blogg -> getPost(). "</p></div>";
			$ret .= "</div>";
		}
		
		return $ret;
	}
	//Skapar html för att göra nya poster
	public function DoNewPost() {
		$html = "<div>
				<h3>New Post</h3>
					<form method ='post' action='index.php?page=newpost'/>
						<h4>Title</h4>
								<input type='text' name='$this->title'/></br>
						Post:</br>
								<textarea type='text' rows='20' cols='60' name='$this->post'></textarea></br>
						<input type='submit' value='Submit' class='css3button' name='$this->submit'/>
					</form>
			</div>";
		return $html;
	}
	//Skapar html för att redigera poster
	public function DoEditPost(\Model\Blogg $blogg) {
		$this -> titlee = $blogg -> getTitle();
		$this -> poste = $blogg -> getPost();
		$html = "<div>
				<h3>Edit Post</h3>
					<form method ='post' action=''/>
						<h4>Title</h4>
								<input type='text' name='$this->title' value='$this->titlee'/></br>
						Post:</br>
								<textarea type='text' rows='10' cols='30' name='$this->post'>$this->poste</textarea></br>
						<input type='submit' value='Submit' class='css3button' name='$this->editSubmit'/>
					</form>
			</div>";
		return $html;
	}

	// Dessa funktoner knyter samman det som man skrivit eller tryckt på så att de kan få värden 
	public function TriedToDelete() {
		if (isset($_POST[$this -> delete]) == true) {
			return true;
		}
		return FALSE;
	}

	public function TriedToEdit() {
		if (isset($_POST[$this -> edit]) == true) {
			return true;
		}
		return FALSE;
	}

	public function PostTitle() {
		if (isset($_POST[$this -> title]) == true) {
			return $_POST[$this -> title];
		}
		return null;
	}

	public function NewPost() {
		if (isset($_POST[$this -> post]) == true) {
			return $_POST[$this -> post];
		}
		return null;
	}

	public function EditTitle() {
		if (isset($_POST[$this -> title]) == true) {
			return $_POST[$this -> title];
		}
		return null;
	}

	public function EditPost() {
		if (isset($_POST[$this -> post]) == true) {
			return $_POST[$this -> post];
		}
		return null;
	}

	public function TriedToSubmit() {
		if (isset($_POST[$this -> submit]) == true) {
			return true;
		}
		return false;
	}

	public function TriedToSubmitEdit() {
		if (isset($_POST[$this -> editSubmit]) == true) {
			return true;
		}
		return false;
	}

	public function Message($status) {
		switch ($status) {
			case self::NOT_EMPTY :
				return "<p>You need to write somthing</p>";
				break;
			case self::POST_PASSED :
				return "<p>You post was a sucsess</p>";
				break;
			case self::POST_FAILED :
				return "<p>You post was a failure</p>";
				break;
			case self::POST_DELETED :
				return "<p>Youre Delete was a sucsess</p>";
				break;
			case self::POST_NOT_DELETED :
				return "<p>Youre Delete was a failure</p>";
				break;
			case self::POST_SAVED :
				return "<p>SAVED</p>";
				break;
			default;
				break;
		}
	}

}
